/*
 * Joysticks.cpp
 *
 *  Created on: Feb 7, 2012
 *      Author: trwulff
 */



/*
 * Default constructor
 */

#ifndef JOYSTICKS_CPP_
#define JOYSTICKS_CPP_
#include "Joysticks.hpp"

// class toggle
#ifdef TOGGLE
toggle::toggle(bool InitialState)
{
		LastValue = InitialState;
		Value = InitialState;
}

toggle::~toggle()
{
	
}

void toggle::Reset()
{
	Value=false;
}
	void toggle::Set()
{
	Value=true;
}

	void toggle::ModifyValue(bool &value)
	{
		if(!LastValue&&value)Value=!Value;
		LastValue=value;
		value = Value;
	}
#endif
	// end toggle
	
	// class SimpleDeadband
	SimpleDeadband::SimpleDeadband(float band){Band=band;}
	SimpleDeadband::~SimpleDeadband(){}
	void SimpleDeadband::Setband(float band){Band=band;}
	float SimpleDeadband::Getband(){return Band;}
	void SimpleDeadband::ModifyValue(float &value)
	{
		
		if (value>Band){
			value= (value-Band)/(1-Band);
		}
		else if(value < -Band)
		{
			value=  (value+Band)/(1-Band);
		}
		else
		{
			value=  0.0;
		}
		

	}
	

	//end SimpleDeadband

	// XBox360 class
XBox360::XBox360(UINT32 port):Joystick(port)
{
	
}


/*
 * Default destructor
 */
XBox360::~XBox360()
{
	
}

float XBox360::GetLeftStickX()
{
	return Joystick::GetRawAxis(kLeftStickX);
}


float XBox360::GetLeftStickY()
{
	return Joystick::GetRawAxis(kLeftStickY);
}

float XBox360::GetRightStickX()
{
	return Joystick::GetRawAxis(kRightStickX);	
}

float XBox360::GetRightStickY()
{
	return Joystick::GetRawAxis(kRightStickY);
}

float XBox360::GetDPad()
{
	return Joystick::GetRawAxis(kDpad);
}

float XBox360::GetDPadX()
{
	return Joystick::GetRawAxis(kRightStickY);
}

float XBox360::GetDPadY()
{
	return Joystick::GetRawAxis(kRightStickY);
}

float XBox360::GetTrigger()//
{
	return Joystick::GetRawAxis(kTrigger);
}

bool XBox360::GetLeftTrigger()
{
	return 1==Joystick::GetRawAxis(kTrigger);
}

bool XBox360::GetRightTrigger()
{
	return -1==Joystick::GetRawAxis(kTrigger);
}

bool XBox360::GetButtonA()
{
	return Joystick::GetRawButton(kButtonA);
}

bool XBox360::GetButtonB()
{
	return Joystick::GetRawButton(kButtonB);
}

bool XBox360::GetButtonX()
{
	return Joystick::GetRawButton(kButtonX);
}

bool XBox360::GetButtonY()
{
	return Joystick::GetRawButton(kButtonY);
}

bool XBox360::GetButtonLeftBumper()
{
	return Joystick::GetRawButton(kButtonLeftBumper);
}

bool XBox360::GetButtonRightBumper()
{
	return Joystick::GetRawButton(kButtonRightBumper);
}

bool XBox360::GetButtonBack()
{
	return Joystick::GetRawButton(kButtonBack);
}

bool XBox360::GetButtonStart()
{
	return Joystick::GetRawButton(kButtonStart);
}

bool XBox360::GetButtonLeftStick()
{
	return Joystick::GetRawButton(kButtonLeftStick);
}

bool XBox360::GetButtonRightStick()
{
	return Joystick::GetRawButton(kButtonRightStick);
}

// end XBox360

// Attack3 class
/*
 *     	static const UINT32 kStickX = 1;
      	static const UINT32 kStickY = 2;
    	static const UINT32 kThrottle = 3;// note: this is assumed not known
     	static const UINT32 kTrigger = 1;
     	static const UINT32 kLeftStickButton = 4;
     	static const UINT32 kMiddleStickButton = 3;
     	static const UINT32 kRightStickButton = 5;
     	static const UINT32 kRearStickButton = 2;
     	static const UINT32 kLeftFrontBaseButton = 6;
     	static const UINT32 kLeftRearBaseButton = 7;
     	static const UINT32 kRightFrontBaseButton = 11;
     	static const UINT32 kRightRearBaseButton = 10;
    	static const UINT32 kLeftBackButton = 8;
    	static const UINT32 kRightBackButton = 9;
 * 
 */
Attack3::Attack3(UINT32 port):Joystick(port)
{

}


/*
* Default destructor
*/
Attack3::~Attack3()
{

}

float Attack3::GetStickX()//Get X value for given axis
{
return Joystick::GetRawAxis(kStickX);
}

float Attack3::GetStickY()//Get Y value for given axis
{
return Joystick::GetRawAxis(kStickY);
}

float Attack3::GetThrottle()//Get X value for given axis
{
return Joystick::GetRawAxis(kThrottle);
}


bool Attack3::GetTrigger()// Get value for given button
{
return Joystick::GetRawButton(kTrigger);
}

bool Attack3::GetLeftStickButton()// Get value for given button
{
return Joystick::GetRawButton(kLeftStickButton);
}

bool Attack3::GetMiddleStickButton()// Get value for given button
{
return Joystick::GetRawButton(kMiddleStickButton);
}

bool Attack3::GetRightStickButton()// Get value for given button
{
return Joystick::GetRawButton(kRightStickButton);
}

bool Attack3::GetRearStickButton()// Get value for given button
{
return Joystick::GetRawButton(kRearStickButton);
}

bool Attack3::GetLeftFrontBaseButton()// Get value for given button
{
return Joystick::GetRawButton(kLeftFrontBaseButton);
}

bool Attack3::GetLeftRearBaseButton()// Get value for given button
{
return Joystick::GetRawButton(kLeftRearBaseButton);
}

bool Attack3::GetRightFrontBaseButton()// Get value for given button
{
return Joystick::GetRawButton(kRightFrontBaseButton);
}

bool Attack3::GetRightRearBaseButton()// Get value for given button
{
return Joystick::GetRawButton(kRightRearBaseButton);
}

bool Attack3::GetLeftBackButton()// Get value for given button
{
return Joystick::GetRawButton(kLeftBackButton);
}

bool Attack3::GetRightBackButton ()// Get value for given button
{
return Joystick::GetRawButton(kRightBackButton);
}



// end Attack3

#endif
//endif JOYSTICKS_CPP_]
